import re

# \b 匹配单词边界: 单词边界是指单词字符 非(字母, 数字, 下划线)
# \bfoo\b (foo),[foo],{foo}, foo ,
ret = re.search(r"\bfoo\b", "foo def")
"<re.Match object; span=(0, 3), match='foo'>"
ret = re.search(r"\bfoo\b", "foo_def")
""
ret = re.search(r"\bfoo\b", "foo3_def")
""

# \B 匹配非单词边界
# \Bfoo\B
ret = re.search(r"\Bfoo\B", "123 foo def")
""
ret = re.search(r"\Bfoo\B", "123_foo_def")
"<re.Match object; span=(4, 7), match='foo'>"

# \d 等价于 集合[0-9]
ret = re.search(r"\d\d0", "call 110 to find help")
"<re.Match object; span=(0, 3), match='110'>"
# \D \d取反

# \s 等价于 集合[\t\n\r\f\v]
ret = re.search(r"\sfoo\s", " abc foo\n baz")
# \S \s取反

# \w 等价于 集合[a-zA-Z0-9_]
ret = re.search(r"abc \w baz", "abc foo baz")

print(ret)
